﻿using Pb;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NNCoinJoinRoom : MonoBehaviour
{

    public GameObject CommonBtn;
    public GameObject LocalTyrantBtn;
    public GameObject ExtremeBtn;
    public GameObject HundredBtn;

    public List<UILabel> baseScore;
    public List<UILabel> limitScore;
    private static NNCoinJoinRoom _instance;
    public NN_ROOM_TYPE _current_type = new NN_ROOM_TYPE();
    public GameObject DNHall_ui;
    public bool _isChange=false;
    public static NNCoinJoinRoom Instance
    {
        get
        {
            return _instance;
        }
    }
    private void Awake()
    {
        _instance = this;
        UIEventListener.Get(CommonBtn).onClick = ButtonClick;
        UIEventListener.Get(LocalTyrantBtn).onClick = ButtonClick;
        UIEventListener.Get(ExtremeBtn).onClick = ButtonClick;
        UIEventListener.Get(HundredBtn).onClick = ButtonClick;
    }

    private void Start()
    {
        EginUser user = EginUser.Instance;
        for (int i = 0; i < 3; i++)
        {

            string str = user.ReturnRelCoinForBrief(user.nnRoomList[i].BaseScore);
            //Debug.Log(str);
            baseScore[i].text = str;
            string str1 = user.ReturnRelCoinForBrief(user.nnRoomList[i].EnterLimit);
            //Debug.Log(str1);
            limitScore[i].text = "准入:" + str1;
        }
    }
    
    public void ResetChange()
    {
        _isChange = false;
    }
    void ButtonClick(GameObject button)
    {

        if (button.name == "CommonBtn")
        {

            SendGetRoomList(1);
            //SendCoinJoinRoom(1);
        }
        else if (button.name == "LocalTyrantBtn")
        {
            SendGetRoomList(2);
            //SendCoinJoinRoom(2);
        }
        else if (button.name == "ExtremeBtn")
        {
            SendGetRoomList(3);
            //SendCoinJoinRoom(3);
        }
        else if (button.name == "HundredBtn")
        {
            Nn100EnterRoomRequest lg = new Pb.Nn100EnterRoomRequest { TypeId = 1 };
            SocketManager socketManager = SocketManager.Instance;
            socketManager.SendProtobuf1(lg, MsgId.Nn100EnterRoomRequest);
        }
    }

    void SendCoinJoinRoom(int typeId)
    {
        EginUser user = EginUser.Instance;
        if (user.gameType == 1)
        {
            //麻将
            MahjongRandomEnterRoomRequest RR = new Pb.MahjongRandomEnterRoomRequest { TypeId = typeId };
            SocketManager socketManager = SocketManager.Instance;
            socketManager.SendProtobuf1(RR, MsgId.MahjongRandomEnterRoomRequest);
        }
        else if (user.gameType == 2)
        {
            //牛牛
            NnRandomEnterRoomRequest lg = new Pb.NnRandomEnterRoomRequest { TypeId = typeId };
            SocketManager socketManager = SocketManager.Instance;
            socketManager.SendProtobuf1(lg, MsgId.NnRandomEnterRoomRequest);
        }
        else if (user.gameType == 3)
        {

        }
        else if (user.gameType == 4)
        {

        }
    }




    private void SendGetRoomList(int type)
    {

        //type 0是阿富汗；1是中国； 2是迪拜
        NnRoomListRequest req = new NnRoomListRequest();
        req.GroundType = NN_GROUND_TYPE.Hall;
        req.Page = 1;
        if (type == 1)
        {
            req.RoomType = NN_ROOM_TYPE.Primary;

        }
        else if (type == 2)
        {
            req.RoomType = NN_ROOM_TYPE.Middle;

        }
        else if (type == 3)
        {
            req.RoomType = NN_ROOM_TYPE.Senior;

        }
 
        Debug.LogError("-GroundType=" + req.GroundType + "-RoomType=" + req.RoomType + "-Page=" + req.Page);
        SocketManager socketManager = SocketManager.Instance;
        socketManager.SendProtobuf1(req, MsgId.NnRoomListRequest);
        if (_current_type!=req.RoomType)
        {
            _isChange = true;
        }
        _current_type = req.RoomType;
        DNHall_ui.SetActive(true);

    }
    void OnDestory()
    {
        _instance = null;
    }
}